<template>
  <view
    class="content"
    :style="{
      'padding-top': height + 'px',
    }"
  >
    <view
      :style="{
        height: statusBarHeight + 'px',
      }"
    >
    </view>
    <view
      class="head"
      :style="{
        top: statusBarHeight + 'px',
        background:'white'
      }"
    >
      <view class="head_left">
        <u-icon
          name="arrow-left"
          color="#444444"
          size="24"
          :bold="true"
          @click="toBack"
        ></u-icon>
      </view>
      <view class="text">优惠券</view>
    </view>

    <view class="tab_view">
      <u-tabs
        lineWidth="36"
        lineColor="#444444"
        :activeStyle="{
          color: '#444444',
          width: '102rpx',
          height: '50rpx',
          'line-height': '50rpx',
          'text-align': 'center',
          'font-size': '34rpx',
        }"
        :inactiveStyle="{
          color: '#888888',
          width: '102rpx',
          height: '50rpx',
          'line-height': '50rpx',
          'text-align': 'center',
          'font-size': '34rpx',
        }"
        :list="list"
        :scrollable="false"
        :current="current"
        @change="changeList"
      ></u-tabs>
    </view>
    <view class="listItem" v-show="listIndex == 0">
      <couponItem :type="1" :detail="detail" ></couponItem>
      <u-loadmore :status="status" color="#ADADAD" v-if="detail.data>0"/>
    </view>
    <view class="listItem" v-show="listIndex == 1">
      <couponItem :type="2" :detail="detail" :showBtn="false"></couponItem>
      <u-loadmore :status="status" color="#ADADAD" v-if="detail.data>0"/>
    </view>
    <view class="listItem" v-show="listIndex == 2">
      <couponItem :type="3" :detail="detail" :showBtn="false"></couponItem>
      <u-loadmore :status="status" color="#ADADAD" v-if="detail.data>0"/>
    </view>
	<floatingBall></floatingBall>
  </view>
</template>
  
  <script>
import couponItem from "./components/couponItem.vue";
export default {
  components: {
    couponItem,
  },

  data() {
    return {
      height: 0,
      statusBarHeight: 0,
      current: 0,
      listIndex: 0,
      status: "nomore",
      list: [
        {
          name: "未使用",
        },
        {
          name: "已使用",
        },
        {
          name: "已过期",
        },
      ],
      detail:{}
    };
  },
  created() {
    const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度

    this.statusBarHeight = statusBarHeight.statusBarHeight;
    this.$nextTick(() => {
      uni
        .createSelectorQuery()
        .select(".head")
        .boundingClientRect((data) => {
          this.height = data.height;
        })
        .exec();
    });
    this.getCoupon(1)
  },
  methods: {
    toBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    changeList(e) {
      console.log("aaaaaaa", e);
      this.listIndex = e.index;
      if(e.index == 0){
        this.getCoupon(1)
      }else if(e.index == 1){
        this.getCoupon(2)
      }else if(e.index == 2){
        this.getCoupon(3)
      }
    },
    getCoupon(status) {
      this.$http
        .userCoupon({
          status:status
        })
        .then((res) => {
          this.detail = res.data.list;
          // this.xiaoyaoList = data;
          console.log(this.detail, "优惠券列表");
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
  },
};
</script>
  
  <style scoped lang="scss">
.content {
  box-sizing: border-box;
}
.head {
  width: 100%;
  padding: 18rpx 30rpx 47rpx;
  position: fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  z-index: 99;

  .head_left {
    position: absolute;
    left: 30rpx;
  }

  .head_right {
    position: absolute;
    right: 30rpx;
  }

  .text {
    font-size: 36rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 400;
    color: #444444;
  }
}
.tab_view {
  width: 100%;
}
.listItem {
  padding: 40rpx 30rpx;
  box-sizing: border-box;
}
</style>